package com.zhaopin.filter;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 字符编码集
 */
@WebFilter(urlPatterns = "/*")
public class CodeFilter implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    /**
     * 处理拦截请求的操作
     * @param servletRequest
     * @param servletResponse
     * @param filterChain
     * @throws IOException
     * @throws ServletException
     */
    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        HttpServletResponse response= (HttpServletResponse) servletResponse;
        response.setContentType("application/json;charset=utf-8");
        HttpServletRequest request= (HttpServletRequest) servletRequest;
        String uri= request.getRequestURI();
        request.getRemoteAddr();
        if (uri.indexOf("/api/v1/user")>1){

        }
        if (uri.indexOf("/api/v1/admin")>1){

        }
        System.out.println(uri);
        request.setCharacterEncoding("utf-8");
        filterChain.doFilter(request,response);
    }

    @Override
    public void destroy() {

    }
}
